class A {
public static void main(String[] args) {
char a = 'a'; // 'a' = 97
char b = 'b'; // 'b' = 98
System.out.print(a + b + "" + a + b);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 290 |
| b. | Prints: 195195 |
| c. | Prints: 195ab |
| d. | Prints: ab195 |
| e. | Prints: abab |
| f. | Runtime error |
| g. | Compiler error |
| h. | None of the above |
class V {
public static void main (String[] args) {
System.out.print((0.0 * -0.0)+","+(-0.0 * -0.0)+",");
System.out.print((0.0 + -0.0));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 0.0,0.0,0.0 |
| b. | Prints: 0.0,0.0,-0.0 |
| c. | Prints: 0.0,-0.0,0.0 |
| d. | Prints: 0.0,-0.0,-0.0 |
| e. | Prints: -0.0,0.0,0.0 |
| f. | Prints: -0.0,0.0,-0.0 |
| g. | Prints: -0.0,-0.0,0.0 |
| h. | Prints: -0.0,-0.0,-0.0 |
| i. | Runtime error |
| j. | Compiler error |
| k. | None of the above |
class A {
public static void main(String[] args) {
short s1 = 1; //1
char c1 = 1; //2
byte b1 = s1; //3
byte b2 = c1; //4
final short s2 = 1; //5
final char c2 = 1; //6
byte b3 = s2; //7
byte b4 = c2; //8
}
}
What is the result of attempting to compile the program?
| a. | Compiler error at 1 |
| b. | Compiler error at 2 |
| c. | Compiler error at 3 |
| d. | Compiler error at 4 |
| e. | Compiler error at 5 |
| f. | Compiler error at 6 |
| g. | Compiler error at 7 |
| h. | Compiler error at 8 |
| i. | Runtime error. |
| j. | None of the Above |
class N {
public static void main (String[] s) {
byte b = 5;
System.out.println(b<<32);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: -1 |
| b. | Prints: 0 |
| c. | Prints: 1 |
| d. | Prints: 5 |
| e. | Runtime error |
| f. | Compiler error |
| g. | None of the above |
class J {
public static void main (String[] s) {
byte b = 0;
b += ~b >>> 1;
System.out.println(b);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: -128 |
| b. | Prints: -127 |
| c. | Prints: -1 |
| d. | Prints: 0 |
| e. | Prints: 1 |
| f. | Prints: 127 |
| g. | Prints: 128 |
| h. | Runtime Exception |
| i. | Compiler Error |
| j. | None of the Above |
class L {
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
char a = 1;
long b = 2;
System.out.print(m(a)+","+ m(b));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: float,float |
| b. | Prints: float,double |
| c. | Prints: double,float |
| d. | Prints: double,double |
| e. | Compiler error. |
| f. | Runtime error. |
| g. | None of the Above |
class Blue {
public static void main (String[] args) {
int i1 = (Integer.MAX_VALUE + 2);
int i2 = (Integer.MIN_VALUE + 1);
int i3 = (Integer.MIN_VALUE + 2);
int i4 = (Integer.MIN_VALUE + 3);
System.out.println((i1==i2)+","+(i1 ==i3)+","+(i1 ==i4));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: true,false,false |
| e. | Compiler error. |
| f. | Runtime error. |
| g. | None of the Above |
class Beige {
public static void main (String[] args) {
int i = (int)Float.NEGATIVE_INFINITY;
int j = (int)Float.POSITIVE_INFINITY;
int k = (int)Float.NaN;
System.out.println((i == Integer.MIN_VALUE) +
", " + (j == Integer.MAX_VALUE) +
", " + (k == 0));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: false, false, false |
| b. | Prints: false, false, true |
| c. | Prints: true, true, false |
| d. | Prints: true, true, true |
| e. | Compiler error. |
| f. | Run time error. |
1. class Green {
2. public static void main (String args[]) {
3. int[] i = null;
4. Cloneable c = i;
5. i = (int [])c;
6. }
7. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 3. |
| b. | Runtime error at line 3. |
| c. | Compiler error at line 4. |
| d. | Runtime error at line 4. |
| e. | Compiler error at line 5. |
| f. | Runtime error at line 5. |
| g. | Compiles and runs without error. |
class Fuchsia {
public static void main (String[] args) {
System.out.println((short)Integer.MIN_VALUE +
", " + (short)Integer.MAX_VALUE +
", " + (int)(char)Integer.MIN_VALUE +
", " + (int)(char)Integer.MAX_VALUE);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: -32768, 32767, -32768, 32767 |
| b. | Prints: -32768, 32767, 0, 65535 |
| c. | Prints: 0, 0, 0, 0 |
| d. | Prints: 0, -1, 0, 65535 |
| e. | Compiler error. |
| f. | Run time error. |
class A {
static int m(int i) {
System.out.print(i + ",");
return 0;
}
public static void main (String[] args) {
int i = 0;
i = i++ + m(i);
System.out.print(i);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 0,0 |
| b. | Prints: 1,0 |
| c. | Prints: 0,1 |
| d. | Prints: 1,1 |
| e. | Runtime error |
| f. | Compiler error |
| g. | None of the above |
class M {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i = 1;
int j = m(i++) + m(i++) * m(i++) + m(i++);
System.out.print(j % 5);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,2,3,4,1 |
| b. | Prints: 1,2,3,4,2 |
| c. | Prints: 1,2,3,4,3 |
| d. | Prints: 1,2,3,4,4 |
| e. | Prints: 1,2,3,4,5 |
| f. | Runtime error |
| g. | Compiler error |
| h. | None of the above |
class A {}
class B extends A {}
class C extends B {
static void m1(A x) {System.out.print("m1A");}
static void m2(B x) {System.out.print("m2B"); m1(x);}
static void m2(A x) {System.out.print("m2A"); m1(x);}
static void m3(C x) {System.out.print("m3C"); m2(x);}
static void m3(B x) {System.out.print("m3B"); m2(x);}
static void m3(A x) {System.out.print("m3A"); m2(x);}
public static void main(String[] args) {
m3(new C());
}
}
What is the result of attempting to compile the program?
| a. | Prints: m3Am2Am1A |
| b. | Prints: m3Bm2Bm1A |
| c. | Prints: m3Cm2Bm1A |
| d. | Prints: m3Cm2Am1A |
| e. | Compiler error |
| f. | Run time error |
| g. | None of the Above |
class A {}
class B extends A {}
class C {
void m(A x) {System.out.print("A");}
void m(B x) {System.out.print("B");}
public static void main(String[] args) {
C c = new C();
c.m(null);
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: A |
| b. | Prints: B |
| c. | Compiler error. |
| d. | Runtime error. |
| e. | None of the Above |
class L {
static String m(int i) {return "int";}
static String m(float i) {return "float";}
public static void main (String[] args) {
long a = 1;
double b = 2;
System.out.print(m(a)+","+ m(b));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: float,float |
| b. | Prints: float,double |
| c. | Prints: double,float |
| d. | Prints: double,double |
| e. | Compile-time error. |
| f. | Run-time error. |
| g. | None of the Above |
1. class Teal {
2. public static void main (String[] args) {
3. byte b=1;
4. long l=1000;
5. b += l;
6. }
7. }
What is the result of attempting to compile and run the above program?
| a. | Compiler error at line 3. |
| b. | Runtime error at line 3. |
| c. | Compiler error at line 4. |
| d. | Runtime error at line 4. |
| e. | Compiler error at line 5. |
| f. | Runtime error at line 5. |
| g. | Compiles and runs without error. |
class R {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
m(m(~1) + m(1|2) + m(1&2) + m(1^3) + m(1<<1));
}
}
What is the result of attempting to compile and run the above program?
| a. | Prints: -2, 3, 0, 3, 0, 6 |
| b. | Prints: -2, 3, 0, 2, 1, 4 |
| c. | Prints: -2, 3, 0, 2, 2, 5 |
| d. | Prints: -2, 3, 0, 3, 2, 6 |
| e. | Prints: -1, 3, 0, 3, 2, 7 |
| f. | Prints: -2, 0, 3, 3, 0, 6 |
| g. | Prints: -1, 0, 3, 2, 1, 4 |
| h. | Prints: -2, 0, 3, 2, 2, 5 |
| i. | Prints: -2, 0, 3, 3, 2, 6 |
| j. | Prints: -1, 0, 3, 3, 2, 7 |
| k. | Runtime error |
| l. | Compiler error |
| m. | None of the above |